#!/bin/bash

# check root permissions
if [[ $EUID -ne 0 ]]; then
echo "Error:This script must be run as root!"
exit 1
fi

# allow root user to log in
LASTLINE=$(tail -n 1 /root/./.profile)
STR="tty -s && mesg n"

if [ "$LASTLINE" != "$STR" ];then
passwd root
cd /usr/share/lightdm/lightdm.conf.d/

cat > ./50-ubuntu.conf <<EOF
[Seat:*]
greeter-session=unity-greeter
user-session=ubuntu
greeter-show-manual-login=true
all-guest=false
EOF

cd /root
sed -i '$d' ./.profile
echo "tty -s && mesg n" >> ./.profile

reboot
fi

systemctl stop apt-daily.service
systemctl stop apt-daily.timer
systemctl stop apt-daily-upgrade.service
systemctl stop apt-daily-upgrade.timer
systemctl disable apt-daily.service
systemctl disable apt-daily.timer
systemctl disable apt-daily-upgrade.service
systemctl disable apt-daily-upgrade.timer

# back up sources 
if [ ! -f "/etc/apt/sources.list.bak" ];then
cp /etc/apt/sources.list /etc/apt/sources.list.bak
fi

chmod 777 /etc/apt/sources.list

# edit sources
echo "\
\
#----------------------------------------------------------------------------------------------------------------
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse
#-----------------------------------------------------------------------------------------------------------------
" \
> /etc/apt/sources.list

# support 32 bit
dpkg --add-architecture i386

# apt-get update
apt-get update

# install git
apt-get -y install git

# install python2
apt-get -y install python python-pip
python2 -m pip install --upgrade pip

# install gdb gcc g++
apt-get -y install gdb gcc g++

# sudo apt-get -y install lib32z1
apt-get -y install libc6-dev-i386

# install peda
cd ~
git clone https://github.com/longld/peda.git ~/peda
echo "source ~/peda/peda.py" >> ~/.gdbinit

# install Pwngdb
cd ~
git clone https://github.com/scwuaptx/Pwngdb.git 
cp ~/Pwngdb/.gdbinit ~/

# download the libc source to current directory(you can use gdb with this example command: directory ~/glibc-2.23/malloc/)
apt-get source libc6-dev

# install curl
apt-get -y install curl

# install pwntools
python2 -m pip install pwntools

# install one_gadget
apt-get -y install ruby
apt-get -y install gem
gem install one_gadget

# install LibcSearcher
cd ~
git clone https://github.com/lieanu/LibcSearcher.git
cd ./LibcSearcher
python2 setup.py develop

# install zsh
cd ~
apt-get -f -y install zsh

LASTSTR=$(tail -n 1 /etc/hosts)
STRING="199.232.28.133 raw.githubusercontent.com"

if [ "$LASTSTR" != "$STRING" ];then
echo "$STRING" >> /etc/hosts
fi

# install ohmyzsh
sh -c "$(wget https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh -O -)"
chsh -s `which zsh`

echo "Installation completed. Please restart."


